home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 001-025 / disk_010 / trek73 / src / cmds1.c next >
C/C++ Source or Header  |  1992-05-06  |  10KB  |  499 lines

  1. /*
  2.  * TREK73: cmds1.c
  3.  *
  4.  * User Commands
  5.  *
  6.  * fire_phasers, fire_tubes, lock_phasers, lock_tubes
  7.  * turn_phasers, turn_tubes, load_tubes, launch_probe,
  8.  * probe_control
  9.  *
  10.  */
  11.  
  12. #include "defines.h"
  13. #include "structs.h"
  14.  
  15. extern    char title[];
  16. extern    char science[];
  17. extern    char engineer[];
  18. extern  char nav[];
  19. extern    char helmsman[];
  20.  
  21. fire_phasers(sp) 
  22. struct ship *sp;
  23. {
  24.     char    buf1[20];
  25.     char    buf2[20];
  26.     char    c;
  27.     int    typed[4];
  28.     register int i;
  29.     register int k;
  30.  
  31.     for (i=0; i<4; i++)
  32.         typed[i] = 0;
  33.     printf("   fire phasers [1-4] ");
  34.     if (Gets(buf1) == NULL)
  35.         return 0;
  36.     printf("   spread [10-45] ");
  37.     if (Gets(buf2) == NULL)
  38.         return 0;
  39.     i = atoi(buf2);
  40.     if (i < 10 || i > 45)
  41.         return 0;
  42.     sp->p_spread = i;
  43.     for (i=0; c = buf1[i]; i++) {
  44.         k = c - '1';
  45.         if (k < 0 || k > 3)
  46.             continue;
  47.         typed[k]++;
  48.         if ((sp->phasers[k].status & P_DAMAGED) ||
  49.             (sp->phasers[k].status) & P_FIRING)
  50.             continue;
  51.         sp->phasers[k].status |= P_FIRING;
  52.     }
  53.     check_p_damage(typed, sp, "fire");    /* Type out if damaged */
  54.     check_p_turn(typed, sp, 1);
  55.     return 1;
  56. }
  57.  
  58.  
  59. fire_tubes(sp)
  60. struct ship *sp;
  61. {
  62.     char    buf1[20];
  63.     char    c;
  64.     int    typed[6];
  65.     register int i;
  66.     register int j;
  67.     register int k;
  68.  
  69.     for (i=0; i<6; i++)
  70.         typed[i] = 0;
  71.     printf("   fire tubes [1-6] ");
  72.     if (Gets(buf1) == NULL)
  73.         return 0;
  74.     j = strlen(buf1);
  75.     for (i=0; c = buf1[i]; i++) {
  76.         k = c - '1';
  77.         if (k < 0 || k > 5)
  78.             continue;
  79.         typed[k]++;
  80.         if ((sp->tubes[k].status & T_DAMAGED) ||
  81.             (sp->tubes[k].status & T_FIRING))
  82.             continue;
  83.         sp->tubes[k].status |= T_FIRING;
  84.     }
  85.     check_t_damage(typed, sp, "fire");    /* Type if damaged */
  86.     check_t_turn(typed, sp, 1);
  87.     j = 0;
  88.     for (i=0; i<6; i++) {
  89.         if ((typed[i] == 0) || (!(sp->tubes[i].status & T_FIRING)))
  90.             continue;
  91.         if (sp->tubes[i].load == 0) {
  92.             if (!j)
  93.                 printf("Computer: Tube(s) %d", i + 1);
  94.             else
  95.                 printf(", %d", i + 1);
  96.             j++;
  97.         }
  98.     }
  99.     if (j)
  100.         printf(" have no charge in them.\n");
  101.     return 0;
  102. }
  103.  
  104.  
  105. lock_phasers(sp)
  106. struct ship *sp;
  107. {
  108.     extern    struct ship *ship_name();
  109.     char    buf1[20];
  110.     char    buf2[20];
  111.     int    typed[4];
  112.     char    c;
  113.     struct    ship *ep;
  114.     register int i;
  115.     register int k;
  116.  
  117.     for (i=0; i<4; i++)
  118.         typed[i] = 0;
  119.     if (sp->status & S_COMP) {
  120.         printf("%s:  Impossible %s, our computer is dead.\n", science, title);
  121.         return 0;
  122.     }
  123.     printf("   lock phasers [1-4] ");
  124.     if (Gets(buf1) == NULL)
  125.         return 0;
  126.     printf("   onto whom ");
  127.     if (Gets(buf2) == NULL)
  128.         return 0;
  129.     ep = ship_name(buf2,ENEMYONLY);
  130.     if (ep == NULL)
  131.         return 0;
  132.     for (i=0; c = buf1[i]; i++) {
  133.         k = c - '1';
  134.         if (k < 0 || k > 3)
  135.             continue;
  136.         typed[k]++;
  137.         if (sp->phasers[k].status & P_DAMAGED)
  138.             continue;
  139.         sp->phasers[k].target = ep;
  140.     }
  141.     check_p_damage(typed, sp, "lock");
  142.     check_p_turn(typed, sp, 0);
  143.     return 1;
  144. }
  145.  
  146.  
  147. lock_tubes(sp)
  148. struct ship *sp;
  149. {
  150.     extern    struct ship *ship_name();
  151.     char    buf1[20];
  152.     char    buf2[20];
  153.     int    typed[6];
  154.     char    c;
  155.     struct    ship *ep;
  156.     register int i;
  157.     register int k;
  158.  
  159.     for (i=0; i<6; i++)
  160.         typed[i] = 0;
  161.     if (sp->status & S_COMP) {
  162.         printf("%s:  Impossible %s, our computer is dead.\n", science, title);
  163.         return 0;
  164.     }
  165.     printf("   lock tubes [1-6] ");
  166.     if (Gets(buf1) == NULL)
  167.         return 0;
  168.     printf("   onto whom ");
  169.     if (Gets(buf2) == NULL)
  170.         return 0;
  171.     ep = ship_name(buf2,ENEMYONLY);
  172.     if (ep == NULL)
  173.         return 0;
  174.     for (i=0; c = buf1[i]; i++) {
  175.         k = c - '1';
  176.         if (k < 0 || k > 5)
  177.             continue;
  178.         typed[k]++;
  179.         if (sp->tubes[k].status & T_DAMAGED)
  180.             continue;
  181.         sp->tubes[k].target = ep;
  182.     }
  183.     check_t_damage(typed, sp, "lock");
  184.     check_t_turn(typed, sp, 0);
  185.     return 1;
  186. }
  187.  
  188.  
  189. turn_phasers(sp)
  190. struct ship *sp;
  191. {
  192.     char    buf1[20];
  193.     char    buf2[20];
  194.     char    c;
  195.     int    typed[4];
  196.     register int i;
  197.     register int j;
  198.     register int k;
  199.  
  200.     for (i=0; i<4; i++)
  201.         typed[i] = 0;
  202.     printf("   turn phasers [1-4] ");
  203.     if (Gets(buf1) == NULL)
  204.         return 0;
  205.     printf("   to [0-360] ");
  206.     if (Gets(buf2) == NULL)
  207.         return 0;
  208.     j = atoi(buf2);
  209.     if (j < 0 || j > 360)
  210.         return 0;
  211.     for (i=0; c = buf1[i]; i++) {
  212.         k = c - '1';
  213.         if (k < 0 || k > 3)
  214.             continue;
  215.         typed[k]++;
  216.         if (sp->phasers[k].status & P_DAMAGED)
  217.             continue;
  218.         sp->phasers[k].target = NULL;
  219.         sp->phasers[k].bearing = j;
  220.     }
  221.     check_p_damage(typed, sp, "turn");
  222.     check_p_turn(typed, sp, 0);
  223.     return 1;
  224. }
  225.  
  226.  
  227. turn_tubes(sp)
  228. struct ship *sp;
  229. {
  230.     char    buf1[20];
  231.     char    buf2[20];
  232.     char    c;
  233.     int    typed[6];
  234.     register int i;
  235.     register int j;
  236.     register int k;
  237.  
  238.     for (i=0; i<6; i++)
  239.         typed[i] = 0;
  240.     printf("   turn tubes [1-6] ");
  241.     if (Gets(buf1) == NULL)
  242.         return 0;
  243.     printf("   to [0-360] ");
  244.     if (Gets(buf2) == NULL)
  245.         return 0;
  246.     j = atoi(buf2);
  247.     if (j < 0 || j > 360)
  248.         return 0;
  249.     for (i=0; c = buf1[i]; i++) {
  250.         k = c - '1';
  251.         if (k < 0 || k > 5)
  252.             continue;
  253.         typed[k]++;
  254.         if (sp->tubes[k].status & T_DAMAGED)
  255.             continue;
  256.         sp->tubes[k].target = NULL;
  257.         sp->tubes[k].bearing = j;
  258.     }
  259.     check_t_damage(typed, sp, "turn");
  260.     check_t_turn(typed, sp, 0);
  261.     return 1;
  262. }
  263.  
  264.  
  265. load_tubes(sp)
  266. struct ship *sp;
  267. {
  268.     char    buf1[20];
  269.     char    buf2[20];
  270.     char    c;
  271.     int    load;
  272.     struct    tube *tp;
  273.     register int i;
  274.     register int j;
  275.     register int k;
  276.  
  277.     load = 0;
  278.     printf("   [load or unload] ");
  279.     if (Gets(buf1) == NULL)
  280.         return 0;
  281.     if (*buf1 == 'l' || *buf1 == 'L')
  282.         load++;
  283.     else if (*buf1 != 'u' && *buf1 != 'U')
  284.         return 0;
  285.     printf("   tubes [1-6] ");
  286.     if (Gets(buf2) == NULL)
  287.         return 0;
  288.     for (i=0; c = buf2[i]; i++) {
  289.         if (sp->energy <= 0)
  290.             break;
  291.         k = c - '1';
  292.         if (k < 0 || k > 5)
  293.             continue;
  294.         tp = &sp->tubes[k];
  295.         if (tp->status & T_DAMAGED)
  296.             continue;
  297.         if (load) {
  298.             j = min(sp->energy, 10-tp->load);
  299.             if (j == 0)
  300.                 continue;
  301.             sp->energy -= j;
  302.             sp->pods -= j;
  303.             tp->load += j;
  304.         } else {
  305.             j = tp->load;
  306.             if (j == 0)
  307.                 continue;
  308.             sp->energy += j;
  309.             sp->pods += j;
  310.             tp->load = 0;
  311.         }
  312.     }
  313.     printf("%s: tubes now ", engineer);
  314.     for (i=0; i<6; i++) {
  315.         if (sp->tubes[i].status & T_DAMAGED)
  316.             printf(" -- ");
  317.         else
  318.             printf(" %-2d ", sp->tubes[i].load);
  319.     }
  320.     printf(" pods at %d\n", sp->pods);
  321.     return 1;
  322. }
  323.  
  324.  
  325. launch_probe(sp)
  326. struct ship *sp;
  327. {
  328.     extern    char captain[];
  329.     extern    struct list *newitem();
  330.     char    buf1[20];
  331.     int    pods, delay, prox, course;
  332.     struct    ship *target;
  333.     struct    list *lp;
  334.     struct    torpedo *pp;
  335.  
  336.     pods = delay = prox = course = 0;
  337.     target = NULL;
  338.     if (sp->status & S_PROBE) {
  339.         printf("%s: probe launcher destroyed!\n", engineer);
  340.         return 0;
  341.     }
  342.     if (sp->energy < 10) {
  343.         printf("%s: we've not enough power, Captain.\n", engineer);
  344.         return 0;
  345.     }
  346.     printf("%s: %d pods available.\n", engineer, sp->energy);
  347.     printf("%s: number to launch [10+] is ", captain);
  348.     if (Gets(buf1) == NULL)
  349.         return 0;
  350.     pods = atoi(buf1);
  351.     if (pods < 10 || pods > sp->energy)
  352.         return 0;
  353.     printf("   set time delay to [0-15] ");
  354.     if (Gets(buf1) == NULL)
  355.         return 0;
  356.     delay = atoi(buf1);
  357.     if (delay < 0 || delay > 15)
  358.         return 0;
  359.     printf("   set proximity delay to [50+] ");
  360.     if (Gets(buf1) == NULL)
  361.         return 0;
  362.     prox = atoi(buf1);
  363.     if (prox < 50)
  364.         return 0;
  365.     printf("   launch towards [whom, if anyone] ");
  366.     Gets(buf1);
  367.     /*
  368.      * This must be fixed in the near future...
  369.      */
  370.     if (*buf1) {
  371.         target = ship_name(buf1,ENEMYONLY);
  372.         if (target == NULL)
  373.             return 0;
  374.     } else {
  375.         printf("   course [0-360] ");
  376.         if (gets(buf1) == NULL)
  377.             return 0;
  378.         course = atoi(buf1);
  379.         if (course < 0 || course > 360)
  380.             return 0;
  381.         target = NULL;
  382.     }
  383.     /*
  384.      * add a new item to the list of items in space
  385.      */
  386.     lp = newitem(I_PROBE);
  387.     lp->data.tp = MKNODE(struct torpedo, *, 1);
  388.     pp = lp->data.tp;
  389.     pp->from = sp;
  390.     pp->fuel = pods;
  391.     pp->timedelay = delay * 10;
  392.     pp->speed = sp->warp;
  393.     pp->newspeed = 2.0;
  394.     pp->prox = prox;
  395.     pp->target = target;
  396.     pp->course = course;
  397.     pp->x = sp->x;
  398.     pp->y = sp->y;
  399.     pp->id = new_slot();
  400.     /*
  401.      * subtract the pods used
  402.      */
  403.     sp->pods -= pods;
  404.     sp->energy -= pods;
  405.     printf("%s: probe %d away\n",engineer, pp->id);
  406.     return 1;
  407. }
  408.  
  409.  
  410. probe_control(sp)
  411. struct ship *sp;
  412. {
  413.     extern    int rangefind();
  414.     extern    int bearing();
  415.     extern    struct list head;
  416.     extern    struct list *tail;
  417.     register struct list *lp;
  418.     register int i;
  419.     register int j;
  420.     register struct torpedo *pp;
  421.     struct    torpedo *probes[10];
  422.     int    probenum;
  423.     struct    ship *ep;
  424.     int    pnum;
  425.     int    bear;
  426.     int    range;
  427.     char    buf1[20];
  428.     char    *bp;
  429.  
  430.     pnum = 0;
  431.     for (lp = &head; lp != tail; lp = lp->fwd) {
  432.         if (lp->type != I_PROBE)
  433.             continue;
  434.         pp = lp->data.tp;
  435.         if (pp->from != sp)
  436.             continue;
  437.         if (!pnum)
  438.             printf("\nprobe bearng range course time  prox units target\n");
  439.         probes[pnum] = pp;
  440.         pnum++;
  441.         range = rangefind(sp->x, pp->x, sp->y, pp->y);
  442.         bear = bearing(sp->x, pp->x, sp->y, pp->y);
  443.         if (pp->target == NULL)
  444.             bp = "NONE";
  445.         else
  446.             bp = pp->target->name;
  447.         printf(" %2d    %3d   %5d  %3d    %2d  %5d  %3d  %s\n",
  448.             pp->id, bear, range, pp->course, pp->timedelay,
  449.             pp->prox, pp->fuel, bp);
  450.     }
  451.     if (!pnum) {
  452.         printf("%s: what probes?\n", nav);
  453.         return 0;
  454.     }
  455.     printf("%s:  detonate all probes?\n", nav);
  456.     printf("%s:  [yes or no] ", captain);
  457.     if (Gets(buf1) != NULL && (*buf1 == 'Y' || *buf1 == 'y')) {
  458.         printf("%s:  aye, %s\n",nav, title);
  459.         for (i=0; i<pnum; i++)
  460.             probes[i]->timedelay = 0;
  461.         return 1;
  462.     }
  463.     printf("   control probe [#] ");
  464.     if (Gets(buf1) == NULL)
  465.         return 0;
  466.     probenum = atoi(buf1);
  467.     for (i=0; i<pnum; i++)
  468.         if (probes[i]->id == probenum)
  469.             break;
  470.     if (i == pnum)
  471.         return 0;
  472.     probenum = i;
  473.     printf("%s: detonate it?\n", nav);
  474.     printf("%s:  [yes or no] ", captain);
  475.     if (Gets(buf1) != NULL && (*buf1 == 'y' || *buf1 == 'Y')) {
  476.         probes[probenum]->timedelay = 0;
  477.         return 0;
  478.     }
  479.     printf("   lock it onto [whom] ");
  480.     if (Gets(buf1) != NULL && *buf1 != NULL) {
  481.         ep = ship_name(buf1,ENEMYONLY);
  482.         if (ep != NULL) {
  483.             probes[probenum]->target = ep;
  484.             printf("%s: locking.\n", nav);
  485.             return 1;
  486.         }
  487.     }
  488.     printf("   set it to course [0-360] ");
  489.     if (Gets(buf1) == NULL || *buf1 == NULL)
  490.         return 0;
  491.     j = atoi(buf1);
  492.     if (j < 0 || j > 360)
  493.         return 0;
  494.     probes[probenum]->course = j;
  495.     probes[probenum]->target = NULL;
  496.     printf("%s: setting in new course.\n", nav);
  497.     return 1;
  498. }
  499.